import "f2e-server3/src/types/uWebSockets.js"
import { APIContext, LoginUser } from "f2e-server3";
import { ObjectId } from "mongodb";

/** HTTP接口服务相关定义 */
export interface PageRecord {
    page: number;
    pageSize: number;
}
export interface PageParams<T> extends Partial<PageRecord> {
    params?: T;
}
export interface Pager<T> extends PageRecord {
    total: number;
    list: T[];
}
export interface ServerResult<T> {
    success: boolean;
    msg?: string;
    data?: T;
}
export interface FetchAPI<F = never, T = never> {
    (body: F, ctx?: APIContext & { loginUser?: LoginUser }): Promise<ServerResult<T>>;
}

export enum SecurityLevel {
    /** 高风险 */
    high = 'high',
    /** 中风险 */
    medium ='medium',
    /** 低风险 */
    low = 'low',
    /** 未知风险 */
    unknown = 'unknown'
}
export const SecurityLevelList = [
    {
        label: '高风险',
        value: SecurityLevel.high
    },
    {
        label: '中风险',
        value: SecurityLevel.medium
    },
    {
        label: '低风险',
        value: SecurityLevel.low
    },
    {
        label: '未知风险',
        value: SecurityLevel.unknown
    }
]
export interface SecurityRule {
    _id?: ObjectId;
    /** 规则域名 */
    host: string;
    /** 等级 */
    level: SecurityLevel;
    /** 备注 */
    remark?: string;
    createdAt?: Date;
    createdBy?: string;
}

export type WhiteListRule = SecurityRule

export interface AccessLog {
    _id?: ObjectId;
    requestDomain: string;
    clientIp: string;
    requestTime: string;
    macAddress: string;
    browserVersion: string;
    deviceInfo: string;
    deviceUuid: string;
    operatingSystem: string;
    userIdentifier: string;
    extraField: string;
    createdAt?: Date;
    createdBy?: string;
}
